// Fill out your copyright notice in the Description page of Project Settings.
#include "UMGLibrary.h"
#include "../StructAndEnum/StructAndEnum.h"
#include "Kismet/GameplayStatics.h"
#include "../MySQL/MySQLSubsystem.h"




void UUMGLibrary::LoadUIConfig(TMap<FString, FUIConfig>& Config)
{
	Config.Empty();
	static FString Path = TEXT("/Game/UI/Config/UIConfig.UIConfig");
	static UDataTable* UIConfig;
	UIConfig = LoadObject<UDataTable>((UObject*)GetTransientPackage(), *Path);
	if (!UIConfig) return;
	UIConfig->AddToRoot();

	const TMap<FName, uint8*>& RowMap = UIConfig->GetRowMap();
	for (auto & KV:RowMap)
	{
		auto Find = UIConfig->FindRow<FUIConfig>(KV.Key, Path);
		if (Find)
		{
			Config.Add(KV.Key.ToString(), *Find);
		}
	}

}

void UUMGLibrary::AddToRoot(UObject* Object)
{
	if (Object)
	{
		Object->AddToRoot();
	}
}

void UUMGLibrary::RemoveFormRoot(UObject* Object)
{
	if (Object)
	{
		Object->RemoveFromRoot();
	}
}

UMySQLSubsystem* UUMGLibrary::GetMySQLSub(const UObject* WorldContextObject)
{
	UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(WorldContextObject);
	return GameInstance->GetSubsystem<UMySQLSubsystem>();
}

void UUMGLibrary::ShowMessage(const FString& Message, FColor color)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, color, FString::Printf(TEXT("%s"),*Message));
}
